﻿<%@ page language="java" import="java.util.*,cn.jbit.mybatisdemo.entity.*,cn.jbit.mybatisdemo.utils.*" pageEncoding="UTF-8"%>
<%@ include file="common/taglib.jsp"%>
<%@ include file="common/common.jsp"%>

<script type="text/javascript" src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js">

</script>
<script>
	function addEmp() {
		if (document.searchForm.deptno.value == '0'){
            alert('请选择部门!');
            return false;
        }
		window.location = "<%=request.getContextPath()%>/jsp/empCreate.jsp?deptNo="+document.searchForm.deptno.value;
	}
</script>
<%
    request.setCharacterEncoding("utf-8");
	String currentPageNo = request.getParameter("currentPageNo");
	int pageNo = 1;
	int pageSize = 1;
	if (currentPageNo != null && !currentPageNo.equals("")){
		pageNo = Integer.parseInt(currentPageNo);
	}
	String empName = request.getParameter("empName");
	String strDeptNo = request.getParameter("deptno");
	String startDate = request.getParameter("startDate");
	String endDate = request.getParameter("endDate");
	
	int deptNo = 0;
	if (strDeptNo != null){
		deptNo = Integer.parseInt(strDeptNo);
	}
	PageList pageList = empService.findEmpByPage(deptNo, empName, DateUtils.string2Date(startDate), DateUtils.string2Date(endDate), pageNo, pageSize);
	List empList = pageList.getList();
 	request.setAttribute("list",empList);
	request.setAttribute("pageList",pageList);
	List deptList = deptService.findAll();
	request.setAttribute("deptList",deptList);
 %>
<!--新闻列表 -->
<div class="main-text-box">
	<div class="main-text-box-tbg">
		<div class="main-text-box-bbg">
			<form name ="searchForm" id="searchForm" action="<%=request.getContextPath()%>/jsp/empList.jsp" method="post">
		 	<div>
		 				部门：
		 					<select name="deptno">
		 						<option value="0">全部</option>
			        			<c:forEach	var="dept" items="${deptList}">
			        				<option value='${dept.deptno}' <c:if test="${dept.deptno==param.deptno}">selected</c:if>>${dept.dname}</option>
			        			</c:forEach>
	        				</select>
		 				员工姓名<input type="text" name="empName" id="empName" value='${param.empName }'/>
		 				<br/>入职时间从<input type="text" name="startDate" id="startDate" value='${param.startDate }' onFocus="WdatePicker({startDate: '1980-05-01' ,alwaysUseStartDate: true })"/>
		 				至<input type="text" name="endDate" id="endDate" value='${param.endDate }' onFocus="WdatePicker({startDate: '1980-05-01' ,alwaysUseStartDate: true })"/>
		 					<button type="submit" class="page-btn">GO</button>
		 					<button type="button" onclick="addEmp();" class="page-btn">增加</button>
		 					<input type="hidden" name="currentPageNo" value="1"/>
		 					<input type="hidden" name="pageSize" value="10"/>
		 					<input type="hidden" name="totalPageCount" value="${pageList.totalPageCount}"/>
		 	</div>
		 	</form>
			<table cellpadding="1" cellspacing="1" class="admin-list">
				<thead >
					<tr class="admin-list-head">
						<th>员工编号</th>
                        <th>姓名</th>
                        <th>职位</th>
                        <th>入职时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                <c:forEach var="emp" items="${list}" varStatus="status">
                	<tr <c:if test="${status.count%2==0 }">class="admin-list-td-h2"</c:if>>
                		<td><a href='empDetailView.jsp?id=<c:out value="${emp.empNo}"/>'><c:out value="${emp.empNo}"/></a></td>
                		<td><c:out value="${emp.empName}"/></td>
                		<td><c:out value="${emp.job}"/></td>
                		<td><fmt:formatDate value="${emp.hireDate}" pattern="yyyy-MM-dd"/></td>
                		<td><a href='empCreate.jsp?empNo=<c:out value="${emp.empNo}"/>'>修改</a>
                			<a href="javascript:if(confirm('确认是否删除此员工？')) location='<c:url value="empDel.jsp">
				                    <c:param name="empNo" value="${emp.empNo}"/>
				                 </c:url>'">删除</a>
                		</td>
                	</tr> 
                </c:forEach>
                </tbody>
            </table>
            <c:import url="rollPage.jsp" charEncoding="UTF-8">
				<c:param name="formName" value="document.forms[0]"/>
				<c:param name="totalRecordCount" value="${pageList.totalRecordCount}"/>
				<c:param name="totalPageCount" value="${pageList.totalPageCount}"/>
				<c:param name="currentPageNo" value="${pageList.currentPageNo}"/>
  			</c:import> 
        </div>
    </div>
</div>

        